package com.gykj.rtm.controller.admin;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

import javax.naming.AuthenticationException;

import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import com.gykj.admin.common.constants.RespResultConstants;
import com.gykj.admin.common.entity.User;
import com.gykj.admin.common.resp.RespResultJson;
import com.gykj.rtm.facade.admin.LoginFacade;

@Api(value = "用户登录接口")
@RestController
public class LoginControllerFacade {
	
	@Autowired
	LoginFacade loginFacade;
	
	@ApiOperation(value = "用户登录" ,  notes="用户登录调用shrio验证")
    @RequestMapping(value="/login",method=RequestMethod.POST)
    public RespResultJson login(@RequestBody User user) throws AuthenticationException {
		RespResultJson result = new RespResultJson();
        try {
        	//校验用户的输入信息
			if (StringUtils.isEmpty(user.getUserNameEg()) || StringUtils.isEmpty(user.getPwd()))
			{
				 result.setStatus(RespResultConstants.F);
				 result.setMessage("用户或者密码为空");
				 return result;
			} else {
				//调用接口验证用户信息
				result = loginFacade.loginCheck(user);
				if (!result.getStatus()) {
					System.out.println("接口返回的验证失败信息： "+result.getMessage());
					 result.setMessage("验证失败，请确认账号或者密码!");
				}
			}
		} catch (Exception e) {
			e.printStackTrace();
			result.setStatus(false);
			result.setMessage(e.getMessage());
		}
        return result;
    }
    
	@ApiOperation(value = "用户登出" ,  notes="用户登出")
    @RequestMapping(value="/logout",method= RequestMethod.GET)
    public String logout(){
    	return "logout";
    }
}
